#include <stdio.h>
#include <stdlib.h>

#include "graph.h"
#include "set.h"
#include "fifo.h"

struct graph graph_init()
{
	struct graph G;
	G.size =0;
	struct edge arc1;
	struct edge arc2;
	arc1.vs = 0;
	arc1.vt = 1;
	arc2.vs = 1;
	arc2.vt = 2;
	G.edges[0]= arc1;
	G.edges[1]= arc2;
	G.size = 2;
	return G;
}


int reachability(struct graph const * G, unsigned char v0, unsigned char vf)
{
	int k;
	struct edge arc;
  struct fifo* waiting=fifo_empty();
  struct set * passed  = set__empty();
	unsigned char v;
  fifo_push (waiting ,v0);
  set__add(passed, v0);
  while(! fifo_is_empty (waiting))
  {
		v= fifo_top(waiting);
		fifo_pop(waiting);
		if (v==vf)
			return 1;
		for (k=0 ; k< G->size; k++)
		{
			arc = G->edges[k];
			if (arc.vs ==v && !set__find(passed,arc.vt))
			{
				fifo_push(waiting, arc.vt);
				set__add(passed, arc.vt);
			}
		}
	}
	return(0);
}

int main(void)
{
	struct graph G = graph_init();
	int r = reachability (&G , 0 , 2);
	printf( "%d \n", r);
	return(0);
}
